package com.siwei.mes.controller.experiment;

import com.siwei.mes.common.result.ApiResult;
import com.siwei.mes.common.result.Json;
import com.siwei.mes.entity.experiment.ExperimentTask;
import com.siwei.mes.service.experiment.ExperimentTaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import static com.siwei.mes.common.exception.handler.MessageHandler.assertTrue;

/**
 * 试验台账与任务关系相关
 *
 * @author linzi
 * @since 2023-12-18 22:11:48
 */
@Api(value = "试验台账与任务关系")
@RestController
@RequestMapping("experimentTask")
public class ExperimentTaskController {
    @Resource
    private ExperimentTaskService experimentTaskService;


    @ApiOperation(value = "根据试验台账id获取对应任务信息")
    @GetMapping("selectByExperimentId")
    public Json selectByExperimentId(@RequestParam("experimentId") Long experimentId) {
        return Json.succ().data(experimentTaskService.selectByExperimentId(experimentId));
    }

    @ApiOperation(value = "根据试验台账id和任务单号 删除对应关联关系")
    @PostMapping("deleteByExperimentIdAndTaskId")
    public Json deleteByExperimentIdAndTaskId(@RequestBody ExperimentTask entity) {
        Long experimentId = entity.getExperimentId();//试验委托id
        Integer taskId = entity.getTaskId();//任务id
        assertTrue(experimentId == null, "试验委托id为空");
        assertTrue(taskId == null, "任务id为空");
        experimentTaskService.deleteByExperimentIdAndTaskId(experimentId, taskId);
        return Json.succ().data(new ApiResult());
    }
}
